class Solution {
    public int sqSum(int n){
        int sum=0;
        while(n!=0){
            int t=n%10;
            sum+=t*t;
            n/=10;
        }
        return sum;
    }
    public boolean isHappy(int n) {
        int fast=sqSum(n),slow=n;
        while(fast!=slow){
            fast=sqSum(sqSum(fast));
            slow=sqSum(slow);
        }
        return slow==1;
    }
}